<?php

namespace App\Http\Controllers\Article\Merchant;

use App\Http\Controllers\BaseController;
use App\Http\Validate\Article\CategoryValidate;
use App\Service\Article\ArticleCategoryService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Validation\ValidationException;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;

class CategoryController extends BaseController
{
    /**
     * @param Request $request
     * @return JsonResponse
     * @throws ValidationException
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public function operate(Request $request): JsonResponse
    {
        ArticleCategoryService::operate(CategoryValidate::operateValidate($request->all()));
        return $this->success();
    }

    /**
     * @param Request $request
     * @return JsonResponse
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     * @throws ValidationException
     */
    public function operateList(Request $request): JsonResponse
    {
        return $this->success(ArticleCategoryService::operateList(CategoryValidate::operateListValidate($request->all())));
    }

    /**
     * @param Request $request
     * @param int $id
     * @return JsonResponse
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     * @throws ValidationException
     */
    public function detail(Request $request, int $id): JsonResponse
    {
        return $this->success(
            ArticleCategoryService::apiDetail(
                CategoryValidate::merchantDetailValidate($request->merge(["id" => $id])->all())
            )
        );
    }
}
